// ignore: constant_identifier_names
import 'package:bilibili/http/dao/login_dao.dart';

enum HttpMehtod { GET, POST, DELETE, PATCH }

abstract class BaseRequest {
  // ignore: prefer_typing_uninitialized_variables
  var pathParams;
  var useHttps = false;
  String authority() {
    return "localhost:8000";
  }

  HttpMehtod httpMethod();
  String path();

  Uri url() {
    Uri uri;
    var pathStr = path();
    if (pathParams != null) {
      if (path().endsWith("/")) {
        pathStr = "${path()}$pathParams";
      } else {
        pathStr = "${path()}/$pathParams";
      }
    }

    if (useHttps) {
      uri = Uri.https(authority(), pathStr, params);
    } else {
      uri = Uri.http(authority(), pathStr, params);
    }

    if (needLogin()) {
      addHeader(LoginDao.BOARDING_PASS, LoginDao.getBoardingPass());
    }

    return uri;
  }

  bool needLogin();

  Map<String, String> params = {};
  BaseRequest add(String k, Object v) {
    params[k] = v.toString();
    return this;
  }

  Map<String, String> header = {};
  BaseRequest addHeader(String k, Object v) {
    header[k] = v.toString();
    return this;
  }
}
